package io.p2p.stream.turn.protocol;

import io.p2p.stream.turn.handler.udp.DataRelayHandler;
import io.p2p.stream.turn.handler.TurnBaseHandler;
import io.p2p.stream.turn.handler.udp.ClientHeartbeatHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;
@Slf4j
public class UdpProtocolManagerFactory {
    private static final Map<String, TurnBaseHandler> protocolMapping = new HashMap<>();

    static{
        protocolMapping.put(ClientHeartbeatHandler.commandType,new ClientHeartbeatHandler());
        protocolMapping.put(DataRelayHandler.commandType,new DataRelayHandler());
    }

    public static TurnBaseHandler getHandler(String protocol) {
        TurnBaseHandler handlerClass = protocolMapping.get(protocol);

        if(handlerClass == null){
            throw new IllegalArgumentException("Unsupported protocol: " + protocol);
        }

        return handlerClass;
    }
}
